﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Fred
{
    public class Character
    {


        /// <summary>
        /// Graphics of the character
        /// </summary>
        Texture2D sprite;

        /// <summary>
        /// Lifes of the character
        /// </summary>
        int lifes;

        // Speed
        int movementSpeed, attackSpeed;

        /// <summary>
        /// X and Y Positions
        /// </summary>
        float X, Y;

        /// <summary>
        /// Variables used for jumping.
        /// </summary>
        Boolean jumping;
        int jumpStrenght;
        int gravity = 10;

        GameWindow window;
        int alfa;

        public Character(GameWindow Window, Texture2D sprite)
        {
            this.sprite = sprite;
            this.lifes = 3;
            this.X = 150;
            this.Y = 150;
            this.window = Window;
            this.alfa = 1;
            this.jumping = false;
            this.jumpStrenght = 50;
            this.movementSpeed = 5;
            this.attackSpeed = 5;
        }


        /// <summary>
        /// Metod used for move character (re-used later to move objects/monsters too)
        /// </summary>
        /// <param name="character"></param>
        /// <param name="dir"></param>
        public void doMove(Character character, int dir, int moveStrenght)
        {

            int maxHeight = window.ClientBounds.Height;
            int maxWidth = window.ClientBounds.Width;

            //Up
            if (dir == 0)
            {
                if (character.Y > 0)
                {
                    character.Y -= moveStrenght;
                }
            }
            //Right
            else if (dir == 1)
            {
                if (character.X < (maxWidth))
                {
                    character.X += moveStrenght;
                }
            }
            //Down
            else if (dir == 2)
            {
                if (character.Y < (maxHeight))
                {
                    character.Y += moveStrenght;             
                }
            }
            //Left
            else if (dir == 3)
            {
                if (character.X > (0))
                {
                    character.X -= moveStrenght;
                }
            }
        }


        /// <summary>
        /// Update metod. I'll run, and run, and run, like you would run if a dog were running after you.
        /// </summary>
        /// <param name="keyboard"></param>
        public void Update()
        {
            // Check if Up key is pressed on keyboard, so the player can move (in that case, Jump)
            if (GameEvents.isPressed(Keys.Up))
            {
                doMove(this, 0, this.movementSpeed);
            }

            // Now the same for other directions
            if (GameEvents.isPressed(Keys.Right))
            {
                doMove(this, 1, this.movementSpeed);
            }

            if (GameEvents.isPressed(Keys.Down))
            {
                doMove(this, 2, this.movementSpeed);
            }

            if (GameEvents.isPressed(Keys.Left))
            {
                doMove(this, 3, this.movementSpeed);
            }

        }

        /// <summary>
        /// Method Draw, to draw stuff. Ya know, bitches love drawings.
        /// </summary>
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(sprite, new Vector2(this.X, this.Y), new Color(1.0f * alfa,1.0f * alfa,1.0f * alfa,alfa));

        }

        /// <summary>
        /// Method to make your character jump. Feel like Michael Jordan on Space Jam and Believe you can fly. Or like Buzz L.Y, whatever.
        /// </summary>
        /// <param name="character"></param>
        public void doJump(Character character)
        {
            // If the character isn't already jumping. No double jumping here.
            if (!character.jumping)
            {
                character.jumping = true;
                //... cri cri... alguma sugestão?

            }
        }

    }
}
